package com.github.thinwonton.springboot.showcase.web.exception.handle.web;

import com.github.thinwonton.springboot.showcase.web.exception.handle.domain.RestResult;
import com.github.thinwonton.springboot.showcase.web.exception.handle.domain.User;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping(value = "/users", produces = {"application/json;charset=UTF-8"})
public class UserController {

    /**
     * 获取用户列表
     *
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public RestResult<List<User>> list() {
        ArrayList<User> list = new ArrayList<>();
        User user1 = new User();
        user1.setAge(18);
        user1.setId(11L);
        user1.setName("hugo18");

        User user2 = new User();
        user2.setAge(19);
        user2.setId(110L);
        user2.setName("hugo19");

        list.add(user1);
        list.add(user2);

        RestResult<List<User>> restResult = new RestResult<>();
        restResult.setCode(RestResult.OK);
        restResult.setData(list);
        return restResult;
    }

    @RequestMapping(value = "/error", method = RequestMethod.GET)
    public List<User> error(){
        throw new RuntimeException("调用rest接口出问题了");
    }
}